<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="店铺名称" prop="shopName">
        <el-input v-model="queryParams.shopName" placeholder="请输入店铺名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="所属银行" prop="tableName">
        <el-select v-model="queryParams.tableName" placeholder="请选择所属银行" clearable>
          <el-option label="蓝海银行" value="ecs_pay_ease" />
          <el-option label="商业银行" value="ecs_yee_pay" />
          <el-option label="苏商/华通" value="ecs_baofu_merchant" />
        </el-select>
      </el-form-item>
      <el-form-item label="所属产品" prop="productId" v-if="user.userId === 1">
        <el-select v-model="queryParams.productId" placeholder="请选择所属产品" clearable>
          <el-option v-for="item in productList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </el-form-item>

      <el-form-item label="二级商户号" prop="subMerchantId">
        <el-input v-model="queryParams.subMerchantId" placeholder="请输入二级商户号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="入金时间">
        <el-date-picker clearable v-model="dateRange" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
          :picker-options="pickerOptions" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结算状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择结算状态" clearable>
          <el-option label="未结算" :value="0" />
          <el-option label="已结算" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['ecs:depositRecord:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="depositRecordList">
      <el-table-column label="编码" width="80" align="center" prop="id" />
      <el-table-column label="店铺名称" align="center" prop="shopName" />
      <el-table-column label="产品名称" v-if="user.userId === 1" align="center" prop="productName" />
      <el-table-column label="所属银行" align="center" width="100" prop="tableName">
        <template slot-scope="scope">
          <span v-if="scope.row.tableName === 'ecs_pay_ease'">蓝海银行</span>
          <span v-else-if="scope.row.tableName === 'ecs_yee_pay'">商业银行</span>
          <span v-else-if="scope.row.tableName === 'ecs_din_pay'">智付锡商</span>
          <span v-else-if="scope.row.tableName === 'ecs_baofu_merchant'">苏商/华通</span>
        </template>
      </el-table-column>
      <el-table-column label="二级商户号" width="100" align="center" prop="subMerchantId" />
      <el-table-column label="入金账账号" align="center" prop="accountNumber" />
      <el-table-column label="入金金额" align="center" width="100" prop="amount" />
      <el-table-column label="入金时间" align="center" prop="depositDateTime" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.depositDateTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="付款人名称" align="center" prop="payerName" />
      <el-table-column label="付款人账号" align="center" prop="payerAccountNumber" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="是否结算" align="center" width="80" prop="tableName">
        <template slot-scope="scope">
          <span v-if="scope.row.status === 1">已结算</span>
          <span v-else-if="scope.row.status === 0">未结算</span>
          <span v-else>状态异常</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listDepositRecord, delDepositRecord } from "@/api/ecs/depositRecord";
import { getUserProfile } from '@/api/system/user'
import { getAgentUserId } from '@/api/ecs/agent'
import { listProduct } from '@/api/ecs/product'

export default {
  name: "DepositRecord",
  data() {
    return {
      user: {},
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      //日期范围
      dateRange: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入金记录表格数据
      depositRecordList: [],
      productList: [],
      //时间快捷范围
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        shopId: null,
        shopName: null,
        agentId: null,
        platformId: null,
        tableName: null,
        productId: null,
        tableNameRequestId: null,
        merchantId: null,
        subMerchantId: null,
        serialNumber: null,
        bankCode: null,
        accountNumber: null,
        amount: null,
        depositDateTime: null,
        payerName: null,
        payerAccountNumber: null,
        collectionType: null,
        sign: null,
        status: null,
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    getUserProfile().then(response => {
      this.user = response.data;
      if (this.user.userId === 1) {
        listProduct({ pageSize: 10000 }).then(response => {
          this.productList = response.rows;
        });
      }
    });
    this.getList();
  },
  methods: {
    /** 查询入金记录列表 */
    getList() {
      this.loading = true;
      listDepositRecord(this.addDateRange(this.queryParams, this.dateRange, "DepositDate")).then(response => {
        this.depositRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('ecs/depositRecord/export', {
        ...this.queryParams
      }, `入金记录_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
